package cn.ichiva.tushare.analysis.data.国内宏观.价格指数;

import cn.ichiva.tushare.analysis.Config;
import cn.ichiva.tushare.analysis.data.国内宏观.金融.CNM;
import cn.ichiva.tushare.sdk.common.DateUtils;
import cn.ichiva.tushare.sdk.tushare.TuClient;
import cn.ichiva.tushare.sdk.tushare.TuDataCacheAble;
import cn.ichiva.tushare.sdk.tushare.entity.TuRequest;

import java.util.HashMap;
import java.util.LinkedHashMap;

/**
 * 居民消费价格指数
 *
 * 获取2000年到现在的所有数据
 */
public class CPI extends TuDataCacheAble {

    public CPI(TuClient client) {
        super(client);

        TuRequest request = new TuRequest();
        request.setApi("cn_cpi");
        request.setDescribe("获取CPI居民消费价格数据，包括全国、城市和农村的数据");

        HashMap<String,String> paramsMap = new HashMap<>();
        paramsMap.put("start_m","200001");
        paramsMap.put("end_m", DateUtils.lastTUMonthString());
        request.setParams(paramsMap);

        LinkedHashMap<String,String> fieldMap = new LinkedHashMap<>();
        fieldMap.put("month","月份YYYYMM");
        fieldMap.put("nt_val","全国当月至");
        fieldMap.put("nt_yoy","全国同比（%）");
        fieldMap.put("nt_mom","全国环比（%）");
        fieldMap.put("nt_accu","全国累计值");
        fieldMap.put("town_val","城市当值月");
        fieldMap.put("town_yoy","城市同比（%）");
        fieldMap.put("town_mom","城市环比（%）");
        fieldMap.put("town_accu","城市累计值");
        fieldMap.put("cnt_val","农村当月值");
        fieldMap.put("cnt_yoy","农村同比（%）");
        fieldMap.put("cnt_mom","农村环比（%）");
        fieldMap.put("cnt_accu","农村累计值");

        request.setFieldMap(fieldMap);
        setRequest(request);
    }

    public static void main(String[] args) {
        new PPI(new TuClient(Config.url, Config.token))
                .get().ifPresent(System.out::println);
    }
}
